package org.tong.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

//@Component
@Aspect
public class ControllerAspect {


    @Pointcut(value = "execution( * org.tong.controller.*.*(..))")
    public void pointcut() {

    }

    @Around("pointcut()")
    public Object before(ProceedingJoinPoint joinPoint) {
        try {
            StringBuilder sb = new StringBuilder(joinPoint.getSignature().getDeclaringTypeName());
            sb.append("." + joinPoint.getSignature().getName());
            sb.append("(");
            Arrays.stream(joinPoint.getArgs()).forEach(arg -> {
                sb.append(arg.toString());
                sb.append(",");
            });
            sb.append(")");
            System.out.println(sb.toString());
            return joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return throwable.getMessage();
        }
    }
}
